VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "clsDiemDoiTuong"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit
Private m_sMaDT As String
Private m_sTenDT As String
Private m_sLoaiUT As String
Private m_iDiemUT As Integer
Private m_dDiemUT As Double

Public Property Get MaDT() As String
    MaDT = m_sMaDT
End Property

Public Property Let MaDT(ByVal sMaDT As String)
    m_sMaDT = sMaDT
End Property

Public Property Get TenDT() As String
    TenDT = m_sTenDT
End Property

Public Property Let TenDT(ByVal sTenDT As String)
    m_sTenDT = sTenDT
End Property

Public Property Get LoaiUT() As String
    LoaiUT = m_sLoaiUT
End Property

Public Property Let LoaiUT(ByVal sLoaiUT As String)
    m_sLoaiUT = sLoaiUT
End Property

Public Property Get DiemUT() As Double
    DiemUT = m_dDiemUT
End Property

Public Property Let DiemUT(ByVal dDiemUT As Double)
    m_dDiemUT = dDiemUT
End Property

'---------------------------------------------------------------------------------------
' Procedure : SelectAll
' Date      : 27/10/2011
' Purpose   : Load danh sach tat ca record cua table co trong file du lieu
'---------------------------------------------------------------------------------------
Public Function SelectAll() As ADODB.Recordset
   On Error GoTo SelectAll_Error

    Call OpenConnection
    ' Create a Recordset by executing an SQL statement.
    Set SelectAll = g_ObjADOConn.Execute("SELECT * FROM DiemDoiTuong")

   On Error GoTo 0
   Exit Function
SelectAll_Error:
    MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure SelectAll of Class Module clsDiemDoiTuong"
End Function

'---------------------------------------------------------------------------------------
' Procedure : SelectByID
' Date      : 27/10/2011
' Purpose   : Lay record cua table ung voi ma DiemDoiTuong truyen vao
'---------------------------------------------------------------------------------------
Public Function SelectByID(ByVal id As String) As ADODB.Recordset
   On Error GoTo SelectByID_Error

    Call OpenConnection
    ' Create a Recordset by executing an SQL statement.
    Set SelectByID = g_ObjADOConn.Execute("SELECT * FROM DiemDoiTuong WHERE MaDT = '" & id & "'")

   On Error GoTo 0
   Exit Function
SelectByID_Error:
    MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure SelectByID of Class Module clsDiemDoiTuong"
End Function

'---------------------------------------------------------------------------------------
' Procedure : Insert
' Date      : 27/10/2011
' Purpose   : Them 1 record moi vao table trong file du lieu
'---------------------------------------------------------------------------------------
Public Function Insert(ByVal ObjDiemDoiTuong As clsDiemDoiTuong) As Boolean
    
   On Error GoTo Insert_Error

    Call OpenConnection
    g_ObjADOConn.Execute ("INSERT INTO DiemDoiTuong(MaDT, TenDT, LoaiUT, DiemUT) " & _
                          "VALUES('" & ObjDiemDoiTuong.MaDT & "', '" & ObjDiemDoiTuong.TenDT & "', '" & ObjDiemDoiTuong.LoaiUT & "', '" & ObjDiemDoiTuong.DiemUT & "')")
    Call CloseConnection
    Insert = True
    
   On Error GoTo 0
   Exit Function
Insert_Error:
    Insert = False
    MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure Insert of Class Module clsDiemDoiTuong"
End Function

'---------------------------------------------------------------------------------------
' Procedure : Delete
' Date      : 27/10/2011
' Purpose   : Xoa 1 record cua table trong file du lieu
'---------------------------------------------------------------------------------------
Public Function Delete(ByVal id As String) As Boolean
   On Error GoTo Delete_Error

    Call OpenConnection
    g_ObjADOConn.Execute ("DELETE FROM DiemDoiTuong WHERE MaDT='" & id & "'")
    Call CloseConnection
    Delete = True
    
   On Error GoTo 0
   Exit Function
Delete_Error:
    Delete = False
    MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure Delete of Class Module clsDiemDoiTuong"
End Function

'---------------------------------------------------------------------------------------
' Procedure : Update
' Date      : 27/10/2011
' Purpose   : Update record cua table dua tren ID truyen vao
'---------------------------------------------------------------------------------------
Public Function Update(ByVal ObjDiemDoiTuong As clsDiemDoiTuong) As Boolean
   On Error GoTo Update_Error

    Call OpenConnection
    g_ObjADOConn.Execute ("UPDATE DiemDoiTuong " & _
                          "SET TenDT = '" & ObjDiemDoiTuong.TenDT & "', " & _
                              "LoaiUT = '" & ObjDiemDoiTuong.LoaiUT & "', " & _
                              "DiemUT = '" & ObjDiemDoiTuong.DiemUT & "'" & _
                          "WHERE MaDT = '" & ObjDiemDoiTuong.MaDT & "'")
    Call CloseConnection
    Update = True

   On Error GoTo 0
   Exit Function
Update_Error:
    Update = False
    MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure Update of Class Module clsDiemDoiTuong"
End Function

